package com.xjc.business.controller.stu;

import com.xjc.business.entity.po.stu.LeaveApplyPo;
import com.xjc.business.entity.vo.stu.HistoryLeaveApplyVo;
import com.xjc.business.entity.vo.stu.LeaveApplyVo;
import com.xjc.business.service.StudentLeaveApplysService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 徐锦程
 * 时间:2025-02-04 20:59
 */
@RestController
@RequestMapping("/student/leave_apply")
public class StuLeaveApplyController {

    @Autowired
    StudentLeaveApplysService studentLeaveApplysService;

    /**
     * 获取当前学生的请假申请
     * @param id 微信Id
     * @return Result
     */
    @GetMapping("/get_current_leave_apply/{id}")
    public Result<LeaveApplyVo> getCurrentLeaveApply(@PathVariable(value = "id", required = false) Integer id){
        if (id == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return studentLeaveApplysService.getCurrentLeaveApply(id);
    }

    /**
     * 添加请假申请
     * @param leaveApplyPo 请假申请
     * @return Result
     */
    @PostMapping("/add_leave_apply")
    public Result<String> addLeaveApply(@RequestBody(required = false) LeaveApplyPo leaveApplyPo){

        return studentLeaveApplysService.addLeaveApply(leaveApplyPo);
    }

    /**
     * 获取历史请假申请
     * @param id 微信Id
     * @return Result
     */
    @GetMapping("/get_history_leave_apply_list/{id}")
    public Result<List<HistoryLeaveApplyVo>> getHistoryLeaveApplyList(@PathVariable(value = "id",required = false) Integer id){
        if (id == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return studentLeaveApplysService.getHistoryLeaveApplyList(id);
    }

    /**
     * 出示二维码
     * @param id 请假记录Id
     * @return Result
     */
    @GetMapping("/show_code/{id}")
    public Result<String> showCode(@PathVariable(value = "id",required = false) Integer id){
        if (id == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return studentLeaveApplysService.showCode(id);
    }
}